package com.dgshanger.sanhxiaofeisc.mvp.presenter

import com.dgshanger.sanhxiaofeisc.entity.ShoppingVideoEntity
import com.dgshanger.sanhxiaofeisc.mvp.contract.ShoppingVideoContract
import com.dgshanger.sanhxiaofeisc.mvp.model.ShoppingVideoModel
import com.xx.baseuilibrary.mvp.BaseMvpPresenter
import com.xx.baseutilslibrary.network.rx.XxBaseHttpObserver

/**
 * Created by JacobHHH on 2018/4/20.
 */
class ShoppingVideoPresenter : BaseMvpPresenter<ShoppingVideoContract.Model, ShoppingVideoContract.View>(), ShoppingVideoContract.Presenter {

    override fun loadData(isRefresh: Boolean, page: String?) {
        getModel().loadData(page,object : XxBaseHttpObserver<List<ShoppingVideoEntity>>(){
            override fun onCompleted(msg: String?, entity: List<ShoppingVideoEntity>?) {
                if (isRefresh){
                    getView()?.setData(entity)
                }else{
                    getView()?.loadMoreData(entity)
                }

            }

            override fun onError(error: String?) {
                getView()?.showError(Throwable(error),isRefresh)
                getView()?.onDataFailure(error)
            }

            override fun onStart() {

            }

            override fun onFinish() {

            }

        })
    }

    override fun createModel(): ShoppingVideoContract.Model = ShoppingVideoModel()
}